package ch.subgate.pongwars;

public class HumanPlayer extends Player {

    /** Stores the delay between the discharge and the ball bounce */
    public float mDischargeDelay;

    /** Determines whether the player is currently being moved */
    public boolean mIsCharging;

    /**
     * Constructs a HumanPlayer object. Sets the discharge delay to 0 and isCharging to true.
     * @param isPlayerRed determines which player the object represents
     * @param size determines the players size
     */
    public HumanPlayer(boolean isPlayerRed, float size) {
        super(isPlayerRed, size);
        mDischargeDelay = 0.0f;
        mIsCharging = true;
    } // Constructor

    /**
     * Updates the player. For the human player this consists only in updating the discharge delay
     * if a discharge has been performed.
     * @param deltaTime Time between two frames in seconds
     */
    @Override
    public void update(float deltaTime) {
        if (!mIsCharging) {
            mDischargeDelay += deltaTime;
        } // if
    } // update

    public void setIsCharging(boolean isCharging) {
        if (isCharging) mDischargeDelay = 0.0f;
        mIsCharging = isCharging;
    } // handleInput

    public void setX(float x) {
        if (x + mSize > Constants.DIC_BATTLEFIELD_WIDTH) { x = Constants.DIC_BATTLEFIELD_WIDTH - mSize; }
        else if (x - mSize < 0) { x = mSize; }
        mLastX = mX;
        mX = x;
        mSpeed = mX - mLastX;
    } // setX

    @Override
    public void reset() {
        super.reset();
        mSpeed = 0.0f;
    } // reset

} // Player
